package ruifeng.zcj.dig.ui.home.recruit;

import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.io.File;
import java.io.IOException;

import butterknife.Bind;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.base.test.Api;
import ruifeng.zcj.dig.ui.home.recruit.bean.Result;
import ruifeng.zcj.mybase.base.BaseFragment;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 招聘
 * Created by Administrator on 2016/8/31 0031.
 */
public class RecruitFragment extends BaseFragment {

    @Bind(R.id.button)
    Button mButton;


    public static RecruitFragment newInstance() {
        Bundle args = new Bundle();
        RecruitFragment fragment = new RecruitFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initFragmentConfig(View view) {

    }

    @Override
    protected int getContentView() {
        return R.layout.fragment_recruit_main;
    }

    @Override
    protected void onFirstUserVisible() {

    }

    @Override
    protected void onUserVisible() {

    }

    @Override
    protected void onUserInvisible() {

    }

    @Override
    protected void cleanMemory() {

    }


    @OnClick(R.id.button)
    public void onClick() {

        String sendpath = null;
        try {
            sendpath = Environment.getExternalStorageDirectory()
                    .getCanonicalPath().toString()
                    + "/DCIM/icon20.png";

        } catch (IOException e) {
            e.printStackTrace();
        }
        final File files = new File(sendpath);

        /*Observable.create(new Observable.OnSubscribe<Result>() {
            @Override
            public void call(Subscriber<? super Result> subscriber) {
                if (!subscriber.isUnsubscribed()) {
                    Observable<Result> ss = Api.getInstance()
                            .movieService
                            .upFile(files.getName(), RequestBody.create(MediaType.parse("image*//*"), files));

                    Result result = null;
                    subscriber.onNext(result);
                    subscriber.onCompleted();//访问结束
                }


            }
        });*/
// Schedulers.io()   .observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
        Api.getInstance()
                .movieService
                .upFile(files.getName(), RequestBody.create(MediaType.parse("image/*"), files))
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Result>() {
            @Override
            public void onCompleted() {
                System.out.println("zcjjdjf");

            }

            @Override
            public void onError(Throwable e) {
                Log.i("zcj", e.getMessage());
            }

            @Override
            public void onNext(Result result) {
                System.out.println("zcj" + result.getMSG());
                System.out.println("zcj" + result.getTOTAL());
            }
        });
    }
}
